package cn.epsilon3.mybatis.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import cn.epsilon3.domain.e3.po.E3UserAuthenticatorPo;
import cn.epsilon3.mybatis.mapper.E3UserAuthenticatorMapper;
import cn.epsilon3.mybatis.service.E3UserAuthenticatorMapperService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * @description 用户验证器表service
 * @author: epsilon3
 * @date: 2023/8/21 14:54
 */
@Service
public class E3UserAuthenticatorMapperServiceImpl implements E3UserAuthenticatorMapperService {

    @Resource
    private E3UserAuthenticatorMapper userAuthenticatorMapper;

    @Override
    @Transactional(readOnly = true)
    public E3UserAuthenticatorPo selectOneByUserId(String userId) {
        return StrUtil.isBlank(userId) ? null : userAuthenticatorMapper.selectOne(Wrappers
                .<E3UserAuthenticatorPo>lambdaQuery()
                .eq(E3UserAuthenticatorPo::getUserId, userId));
    }

    @Override
    @Transactional
    public void insertOne(E3UserAuthenticatorPo e3UserAuthenticatorPo) {
        userAuthenticatorMapper.insert(e3UserAuthenticatorPo);
    }

    @Override
    public void updateOne(E3UserAuthenticatorPo e3UserAuthenticatorPo) {
        userAuthenticatorMapper.updateById(e3UserAuthenticatorPo);
    }
}
